#include <cstdio>
#include <map>
#include <string>
#include <cstring>

using namespace std;

map<string, int> mp;

int n, m, q, f[ 2000 ], money[ 2000 ], mt[ 2000 ];

void init( )
{
    int i;
    char s[ 1010 ];
    string t;
    memset( f, 0, sizeof( f ) );
    memset( money, 0, sizeof( money ) );
    memset( mt, 0, sizeof( mt ) );
    mp.clear( );
    for ( i = 1; i <= n + m; i++ )
        money[ i ] = 603;
    for ( i = 0; i < n; i++ )
    {
        scanf("%s", s);
        t = s;
        mp[ t ] = i + 1;
    }
    for ( i = 0; i < m; i++ )
    {
        scanf("%s", s);
        t = s;
        mp[ t ] = i + 1 + n;
    }
}

void work( )
{
    int i, p1, p2, ti;
    string t;
    bool fb = false;
    char cmd[ 3 ], s1[ 1001 ], s2[ 1001 ];
    while ( q-- )
    {
        scanf("%s", cmd);
        if ( cmd[ 0 ] == 'K' )
        {
            scanf("%s%s%d", s1, s2, &ti);
            t = s1;
            p1 = mp[ t ];
            t = s2;
            p2 = mp[ t ];
            if ( p1 <= n && p2 > n || p1 > n && p2 <= n )
            {
                if ( f[ p1 ] > 1 )
                    money[ p1 ] += ( f[ p1 ] - 1 ) * 50;
                money[ p1 ] += 200;
                if ( !fb )
                {
                    money[ p1 ] += 200;
                    fb = true;
                }
                if ( f[ p1 ] < 9 ) f[ p1 ]++;
            }
            f[ p2 ] = 0;
            money[ p2 ] += ti - mt[ p2 ];
            mt[ p2 ] = ti;
            money[ p2 ] -= 300;
            if ( money[ p2 ] < 0 ) money[ p2 ] = 0;
        }
        else
        {
            scanf("%s%d", s1, &ti);
            t = s1;
            p1 = mp[ t ];
            printf("%d\n", money[ p1 ] + ti - mt[ p1 ]);
        }
    }
}

int main( )
{
    while ( scanf("%d%d%d", &n, &m, &q) != EOF )
    {
        init( );
        work( );
    }
    return 0;
}
